package com.dhq.services;

import java.util.HashSet;
import java.util.Set;

import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrServer;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.HttpSolrServer;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.common.SolrDocument;
import org.apache.solr.common.SolrDocumentList;

public class Test {
	public static void main(String[] args) throws SolrServerException {
		SolrServer solr = new HttpSolrServer("http://localhost:8080/solr");
		SolrQuery query = new SolrQuery();
		//设置查询条件,名称“q”是固定的且必须 的
		query.set("q", "name:"+"中国");
		QueryResponse response = solr.query(query);
		SolrDocumentList docs = response.getResults();
		
		query.setStart(0);
		query.setRows((int) docs.getNumFound());
		// 请求查询
		response = solr.query(query);
		docs = response.getResults();
		// 查询结果
		Set<String> set=new HashSet<String>();
		for (SolrDocument doc : docs) {
			String id = (String) doc.getFieldValue("id");
			set.add(id);
		}

	}
}
